//
//  GetFeedBack_Detaile.swift
//  Pods
//
//  Created by eme on 2017/4/11.
//
//

import UIKit
import RxSwift
import NetWorkCore
import ModelProtocol

class GetFeedBack_Detaile{
    
    let get_complainid = PublishSubject<String>()
    let error = PublishSubject<MikerError>()
    let result = PublishSubject<FeedBackDetaileModel>()
    let refreshing = Variable(false)
    let disposeBag = DisposeBag()
    
    init(){
        
        let request = get_complainid.map{ id in
            return MineApi.getFeedBackDetaile(id: id)
            }.shareReplay(1)
        
        
        let response = request.emeRequestApiForObj(FeedBackDetaileModel.self).shareReplay(1)
        
        response.subscribe(onNext:{ result in
            switch result{
            case .failure(let error):
                self.error.onNext(error)
            case .success(let data):
                self.result.onNext(data)
            }
        }).addDisposableTo(disposeBag)
        
        Observable
            .of(
                request.map { _ in true },
                response.map { _ in false },
                error.map { _ in false }
            )
            .merge()
            .bindTo(refreshing)
            .addDisposableTo(disposeBag)
    }
    
}
